# coding:UTF-8

from django.db import models
from django.contrib import admin
from myblogs.models import BlogInfo
from account.models import UserInfo



class BlogComment(models.Model):
    status = models.CharField(max_length=10, default="True")
    # comment_id = models.IntegerField(default=0)
    from_user = models.ForeignKey(UserInfo, null=True, blank=True)
    # table:blog_comment的一部分叫做"comment_list"
    blog = models.ForeignKey(BlogInfo, related_name="comment_list")
    head_img_url = models.CharField(max_length=100, default="", null=True, blank=True)
    content = models.CharField(max_length=250)
    createTime = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return str(self.pk) + ":" + str(self.createTime)

    class Meta:
        db_table = 'blog_comment'


class BlogCommentAdmin(admin.ModelAdmin):
    list_display = ('pk',
                    'status',
                    'from_user',
                    'blog',
                    'createTime')

    search_fields = ('id',
                     'blog__blog_title',
                     'from_user__username')

    def blocked_comment(modeladmin, request, queryset):
        for comment in queryset:
            comment.status = 'False'
            comment.save()

    blocked_comment.short_description = "屏蔽所选评论"

    actions = ["blocked_comment"]



admin.site.register(BlogComment, BlogCommentAdmin)